package com.lmx.persistence.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.exception.BusinessException;
import com.lmx.repoDomain.tmodel.Activity;
import com.lmx.repoDomain.tmodel.ActivityPlan;

@Service(value = "activityService")
public class ActivityServiceImpl extends BaseCrudServiceImpl<Activity>
		implements ActivityService {

	@Autowired
	private ActivityPlanService planSrv;

	@Override
	public void checkDelete(Activity entity) {
		List<ActivityPlan> plans = this.planSrv.find("activity.id",
				entity.getId());
		if (plans != null && plans.size() > 0) {
			throw new BusinessException("",
					CommonConstants.ACTIVITY_ERROR_CODE.NOT_DELETE.lable(),
					"不能删除");
		}
	}

	@Override
	public void checkRepeat(Activity entity, Long tenantId) {
		Map<String, Object> param = Maps.newHashMap();
		param.put("title", entity.getTitle());
		param.put("delStatus", CommonConstants.DEL_STATUS_NO_0);
		param.put("tenant.id", tenantId);
		List<Activity> activities = super.find(param);
		if (activities != null && activities.size() > 0) {
			throw new BusinessException("",
					CommonConstants.ACTIVITY_ERROR_CODE.INFO_REPEAT.lable(),
					"名字重复");
		}
	}
}
